package logs

import (
	"common/config"
	"github.com/charmbracelet/log"
	"os"
	"time"
)

var Logger *log.Logger

func InitLog(appName string) {
	Logger = log.New(os.Stderr)
	if config.Conf.Log.Level == "DEBUG" {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}
	Logger.SetPrefix(appName)
	Logger.SetReportTimestamp(true)
	Logger.SetTimeFormat(time.RFC3339)
}
func Debug(format string, val ...any) {
	if len(val) == 0 {
		Logger.Debug(format)
	} else {
		Logger.Debug(format, val...)
	}
}

func Info(format string, val ...any) {
	if len(val) == 0 {
		Logger.Info(format)
	} else {
		Logger.Info(format, val...)
	}
}

func Warn(format string, val ...any) {
	if len(val) == 0 {
		Logger.Warn(format)
	} else {
		Logger.Warn(format, val...)
	}
}

func Error(format string, val ...any) {
	if len(val) == 0 {
		Logger.Error(format)
	} else {
		Logger.Error(format, val...)
	}
}

func Fatal(format string, val ...any) {
	if len(val) == 0 {
		Logger.Fatal(format)
	} else {
		Logger.Fatal(format, val...)
	}
}
